import datetime
import random

from info import db
from info.models import User
from manager import app


def add_test_users():
    users = []
    now = datetime.datetime.now()
    # for num in range(4000, 5000):
    #     try:
    user = User()
    user.nick_name = "三胖子"
    user.mobile = "13412345679"
    # user.password = ''# 执行效率较低
    user.password = "12345678"
    user.last_login = now - datetime.timedelta(seconds=random.randint(0, 2678400))
    users.append(user)
            # print(user.mobile)
        # except Exception as e:
        #     print(e)
    # 手动开启一个app的上下文
    with app.app_context():
        db.session.add_all(users)
        db.session.commit()
    print('OK')


if __name__ == '__main__':
    add_test_users()